#include "ET++.ph"
#ifdef __GNUG__
#pragma implementation
#endif

#include "ClassItem.h"

#include "Class.h"
#include "PrintManager.h"
#include "String.h"
#include "Look.h"

//---- PeClassItem -----------------------------------------------------

NewMetaImpl(PeClassItem, TextItem, (TP(cl)));

PeClassItem::PeClassItem(int id, Class *c, const char *label)
		: TextItem(id, c->Name(),
			gFixedFont->WithFace(c->IsAbstract() ? eFaceItalic : eFacePlain),
				Point(2,1))
//                gBorder)
{
	cl= c;
	if (label)
		SetString(label);
}

const char *PeClassItem::ClassName()
{
	return cl->Name();
}

int PeClassItem::Compare(Object *op)
{
	return StrCmp(ClassName(), Guard(op, PeClassItem)->ClassName(), -1,
												gStdEncoding->UpperCaseMap());
}

bool PeClassItem::IsEqual(Object *b)
{
	return b->IsKindOf(PeClassItem) &&
			StrCmp(ClassName(), ((PeClassItem*)b)->ClassName()) == 0;
}

Metric PeClassItem::GetMinSize()
{
	if (TestFlag(eClItemCollapsed))
		return Metric(Point(8));
	return TextItem::GetMinSize();
}

void PeClassItem::DrawInner(Rectangle r, bool highlight)
{
	bool coll= TestFlag(eClItemCollapsed);
	if (!GrHasColor()) {
		if (coll)
			GrPaintRect(ContentRect().Inset(2), ePatGrey50);
		else {
			GrPaintRect(ContentRect(), gInkWhite /*gLook->GetBackgroundColor()*/);
			TextItem::Draw(r);
		}
	}
	if (highlight && ! gPrinting)
		DrawHighlight(r);
	if (GrHasColor()) {
		if (coll)
			GrPaintRect(ContentRect().Inset(2), ePatGrey50);
		else {
			if (!highlight)
				GrPaintRect(ContentRect(), gInkWhite /*gLook->GetBackgroundColor()*/);
			TextItem::Draw(r);
		}
	}
//    BevelRect(contentRect, 2, TRUE, new_Grey(0.15), new_Grey(0.95));
}

//---- ObjectItem --------------------------------------------------------------

NewMetaImpl(PeObjectItem, TextItem, (TP(op)));

PeObjectItem::PeObjectItem(int id, Object *o, Font *fp)
									: TextItem(id, 0, fp, Point(2,1))
{
	char buf[200];
	buf[0]= '\0';
	op= o;
	op->InspectorId(buf, sizeof(buf));
	if (strlen(buf))
		SetFString(FALSE, "0x%x %s", int(op), buf);
	else
		SetFString(FALSE, "0x%x", int(op));
}

PeObjectItem::PeObjectItem(int id, char *msg, Object *o, Font *fp)
									: TextItem(id, 0, fp, Point(2,1))
{
	op= o;
	SetString(msg);
}

PeObjectItem::PeObjectItem(char *iv, Object *o, Font *fp)
									: TextItem(cIdNone, 0, fp, Point(4,0))
{
	op= o;
	SetFString(FALSE, "%s 0x%x", iv, int(op));
}
